package com.fmatos.controller.directory;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fmatos.controller.AlbumsCache;
import com.fmatos.service.album.downloader.info.AlbumInfo;
import com.fmatos.service.album.downloader.info.PinterestAlbumInfo;
import com.fmatos.service.album.downloader.rss.RssAlbumInfo;

// TODO this must be a bean
public class AlbumDirectory {

	private static final Logger LOGGER = LoggerFactory.getLogger(AlbumDirectory.class);
	
	private static List<AlbumInfo> ALL_ALBUMS_LIST = null;
	private static HashMap<String,AlbumInfo> ALL_ALBUMS_HASH_BY_NAME = null;
	
	public static List<AlbumInfo> getAllAlbums() {
		if ( ALL_ALBUMS_LIST == null ) {
			buildAllAlbums();
		}
		
		return ALL_ALBUMS_LIST;
	}

	private static void buildAllAlbums() {

		List<AlbumInfo> list = new LinkedList<AlbumInfo>();
				
		// General
		list.add(new RssAlbumInfo("Imgur","http://feeds.feedburner.com/ImgurGallery?format=xml"));
		list.add(new RssAlbumInfo("9Gag","http://9gagrss.com/feed/"));
		
		list.add(new RssAlbumInfo("Pinterest Fmatos","http://www.pinterest.com/fmatosqg/feed.rss"));
		list.add(new RssAlbumInfo("Anna Kim Photography", "http://www.annakimphotography.com/blog/feed/"));
		
		// World
		list.add(new RssAlbumInfo("Botanical photo of the day","http://www.botanicalgarden.ubc.ca/potd/index.xml"));
		
		list.add(new RssAlbumInfo("Nat Geo of the day","http://feeds.nationalgeographic.com/ng/photography/photo-of-the-day/"));
		list.add(new RssAlbumInfo("Nat Geo environment news","http://feeds.nationalgeographic.com/ng/news/news_environment"));
		list.add(new RssAlbumInfo("Nat Geo space news","http://news.nationalgeographic.com/rss/space.rss")); // small image
		list.add(new RssAlbumInfo("Prague daily photo","http://feeds.feedburner.com/PragueDailyPhoto"));

		// Astronomy
		list.add(new RssAlbumInfo("JPL photojournal","http://photojournal.jpl.nasa.gov/rss/new"));
		list.add(new RssAlbumInfo("JPL news", "http://www.jpl.nasa.gov/multimedia/rss/news.xml")); // small image

		list.add(new RssAlbumInfo("Astronomy Picture of the day","http://www.acme.com/jef/apod/rss.xml"));
		list.add(new RssAlbumInfo("Chandra","http://www.nasa.gov/rss/dyn/chandra_images.rss"));
		list.add(new RssAlbumInfo("Pinterest Hubble","http://www.pinterest.com/hubblesite/feed.rss"));
//		list.add(new RssAlbumInfo("Pinterest Chandra Ray","http://www.pinterest.com/chandraxray/feed.rss"));
		list.add(new PinterestAlbumInfo("Pinterest Chandra Ray","chandraxray"));
		list.add(new PinterestAlbumInfo("Pinterest Chandra Ray","chandraxray","sdas"));
		list.add(new RssAlbumInfo("Chandra Ray Blog","http://chandra.si.edu/blog/rss.xml"));
		
//		http://chandra.si.edu/resources/feeds.html
		// http://chandra.si.edu/blog/big_picture_feed.html -- has no images
		
		// spitzer observatory (no images found over feed
//		http://www.spitzer.caltech.edu/resource_list/2-Featured-Images?format=xml
//		http://www.spitzer.caltech.edu/resource_list/0?format=xml
		
		// various scopes http://amazing-space.stsci.edu/resources/explorations/groundup/lesson/scopes/spitzer/

		// sports
		list.add(new RssAlbumInfo("Dakar feed", "http://www.leblogauto.com/category/sport-auto/dakar/feed/"));
		list.add(new RssAlbumInfo("Dakar on Pinterest","http://pinterest.com/dakarrally/feed.rss")); 
		list.add(new RssAlbumInfo("Dakar feed 2", "http://www.race-dezert.com/home/feed"));
		
		
		// photography
//		http://www.pinterest.com/eyefi/instagram-favorites/
//		http://www.eyefi.com/company/blog/sip?utm_source=email&utm_medium=email&utm_content=sip&utm_campaign=all_jan_2015_webinar
		
		ALL_ALBUMS_HASH_BY_NAME = new HashMap<>();
		
		for ( AlbumInfo album: list) {
			ALL_ALBUMS_HASH_BY_NAME.put(album.getName(), album);

		}
		
		ALL_ALBUMS_LIST = list;
		
	}

	public static AlbumInfo findAlbumByName(String name) {
		if ( ALL_ALBUMS_LIST == null ) {
			buildAllAlbums();
		}
		
		return ALL_ALBUMS_HASH_BY_NAME.get(name);
	}
}
